package com.ruoyi.quartz.task;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.domain.EmailConfig;
import com.ruoyi.system.domain.StuDataCer;
import com.ruoyi.system.domain.StuDataCerState;
import com.ruoyi.system.mapper.StuCertificateMapper;
import com.ruoyi.system.mapper.StuDataCerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Component;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.mail.javamail.JavaMailSender;


import java.util.ArrayList;

import static com.ruoyi.common.config.datasource.DynamicDataSourceContextHolder.log;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{
    @Autowired
    private JavaMailSender javaMailSender;
    @Autowired
    private StuCertificateMapper stuCertificateMapper;
    @Autowired
    private StuDataCerMapper stuDataCerMapper;
    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }


    public void updateExpiredStatus()
    {
        stuCertificateMapper.updateExpiredStatus();
        System.out.println("执行更新过期证书");
    }

    public void emailByExpiredStatus()
    {
        stuCertificateMapper.updateExpiredStatus();
        System.out.println("执行过期证书提醒");
    }

    public void send_1(){
        try{
            ArrayList<StuDataCer> stuDataCers = stuDataCerMapper.getReviewToEmail();
            SimpleMailMessage mailMessage = new SimpleMailMessage();
            //设置发送人
            mailMessage.setFrom(EmailConfig.getEmail());
            //邮件内容
            mailMessage.setText("证书审核未通过！\n请登录系统查看");
            //收件人
            for (StuDataCer stuDataCer : stuDataCers) {
                //邮件主题
                mailMessage.setSubject(stuDataCer.getStuNumber()+"_"+stuDataCer.getStuName()+"你的证书审核未通过！");
                mailMessage.setTo(stuDataCer.getEmail()); // 注意：这将替换之前的收件人列表
                javaMailSender.send(mailMessage);
            }
        } catch(Exception e) {
            log.error("邮箱报错！！"+e.getMessage(), e);
            System.out.println("邮件发送失败！！！");
        }
        System.out.println("执行过期证书提醒");
    }
}
